package com.javalong.affairs.activity;

import java.util.Date;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.javalong.affairs.R;
import com.javalong.affairs.manager.IntentManager;
import com.javalong.affairs.ui.TopTitle;
import com.javalong.affairs.ui.TopTitle.OnRightDrawableClick;
import com.javalong.affairs.utils.DateTimePickDialogUtil;
import com.javalong.affairs.utils.DateUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

@ContentView(R.layout.activity_tasktrack)
public class TaskTrackActivity extends BaseActivity {
	@ViewInject(R.id.ui_toptitle)
	private TopTitle topTitle;
	@ViewInject(R.id.bt_add)
	private Button bt_add;
	@ViewInject(R.id.bt_starttime)
	private Button bt_starttime;
	@ViewInject(R.id.bt_endtime)
	private Button bt_endtime;
	@ViewInject(R.id.tv_starttime)
	private TextView tv_starttime;
	@ViewInject(R.id.tv_endtime)
	private TextView tv_endtime;
	@ViewInject(R.id.ll_task)
	private LinearLayout ll_task;
	private Date nowDate;
	private DateTimePickDialogUtil startDialog;
	private DateTimePickDialogUtil endDialog;
	private LayoutInflater inflater;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ViewUtils.inject(this);
		inflater = LayoutInflater.from(this);
		nowDate = new Date();
		initUI();
	}

	private void initUI() {
		bt_add.setOnClickListener(this);
		bt_starttime.setOnClickListener(this);
		bt_endtime.setOnClickListener(this);
		startDialog = new DateTimePickDialogUtil(this,
				DateUtils.formatDate(nowDate));
		endDialog = new DateTimePickDialogUtil(this,
				DateUtils.formatDate(nowDate));
		topTitle.setOnLeftDrawableClick(this);
	}

	@Override
	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.bt_add:
			addTaskUI();
			break;
		case R.id.bt_starttime:
			startDialog.dateTimePicKDialog(tv_starttime);
			break;
		case R.id.bt_endtime:
			endDialog.dateTimePicKDialog(tv_endtime);
			break;
		}
	}

	private void addTaskUI() {
		LinearLayout.LayoutParams ll_param = new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.MATCH_PARENT,
				LinearLayout.LayoutParams.WRAP_CONTENT);
		View view = inflater.inflate(R.layout.ui_task_item, null);
		ll_task.addView(view, ll_param);
	}
}
